home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / OutOfContextMenus / Source / CCrashedBehavior.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  2.9 KB  |  129 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CCrashedBehavior.cp                 ©1999 Eric Traut
  3. // ===========================================================================
  4.  
  5. #include "CCrashedBehavior.h"
  6. #include "CShadowWindow.h"
  7.  
  8.  
  9. // ---------------------------------------------------------------------------
  10. //        • CCrashedBehavior
  11. // ---------------------------------------------------------------------------
  12.  
  13. CCrashedBehavior::CCrashedBehavior(
  14.     CShadowWindow &        inShadowWindow)
  15.     :    COffscreenBehavior(inShadowWindow, true, true)
  16. {
  17.     mCrashState = 0;
  18. }
  19.  
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • RenderToGWorld
  23. // ---------------------------------------------------------------------------
  24.  
  25. enum
  26. {
  27.     kPixelsToDrawOK            = 3000,
  28.     kPixelsToDrawGarbage    = 1500
  29. };
  30.  
  31. Boolean
  32. CCrashedBehavior::RenderToGWorld(
  33.     StGWorldLocker &        inBackingLocker,
  34.     StGWorldLocker &        inRenderingLocker)
  35. {
  36.     UInt16        row;
  37.     UInt16        column;
  38.     UInt16        maxRow;
  39.     UInt16        maxColumn;
  40.     UInt16        srcRowWords;
  41.     UInt16        destRowWords;
  42.     UInt16 *    srcRowPtr;
  43.     UInt16 *    destRowPtr;
  44.     PixMapPtr    tempPixMap;
  45.     
  46.     mCrashState += 2;
  47.     if (mCrashState > 50)
  48.         mCrashState = 50;
  49.     
  50.     tempPixMap = *inBackingLocker.GetPixMap();
  51.     srcRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  52.     srcRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  53.  
  54.     tempPixMap = *inRenderingLocker.GetPixMap();
  55.     destRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  56.     destRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  57.  
  58.     maxRow = tempPixMap->bounds.bottom - tempPixMap->bounds.top;
  59.     maxColumn = tempPixMap->bounds.right - tempPixMap->bounds.left;
  60.  
  61.     UInt16        pixelValue = 0x5252;
  62.     Boolean        drawGarbage = false;
  63.     UInt32        pixelsLeft = kPixelsToDrawOK;
  64.  
  65.     // Draw garbage in certain strips
  66.     for (row = 0; row < maxRow; row++)
  67.     {
  68.         for (column = 0; column < maxColumn; column++)
  69.         {
  70.             if (drawGarbage)
  71.             {
  72.                 destRowPtr[column] = pixelValue;
  73.                 pixelValue *= 13;
  74.  
  75.                 if (--pixelsLeft == 0)
  76.                 {
  77.                     drawGarbage = false;
  78.                     pixelsLeft = kPixelsToDrawOK;
  79.                 }
  80.             }
  81.             else
  82.             {
  83.                 destRowPtr[column] = srcRowPtr[column];
  84.                 
  85.                 if (--pixelsLeft == 0)
  86.                 {
  87.                     drawGarbage = true;
  88.                     pixelsLeft = kPixelsToDrawGarbage * mCrashState / 5;
  89.                 }
  90.             }
  91.         }
  92.         
  93.         srcRowPtr += srcRowWords;
  94.         destRowPtr += destRowWords;
  95.     }
  96.     
  97.     return true;
  98. }
  99.  
  100.  
  101. // ---------------------------------------------------------------------------
  102. //        • ShouldEnableRestoreMenu
  103. // ---------------------------------------------------------------------------
  104.  
  105. Boolean
  106. CCrashedBehavior::ShouldEnableRestoreMenu(void)
  107. {
  108.     return false;
  109. }
  110.  
  111.  
  112. // ---------------------------------------------------------------------------
  113. //        • HandleEvent
  114. // ---------------------------------------------------------------------------
  115.  
  116. void
  117. CCrashedBehavior::HandleEvent(
  118.     EventRecord *        ioEvent, 
  119.     Boolean *            ioResult)
  120. {
  121.     #pragma unused (ioEvent)
  122.     
  123.     // Swallow all events. We're crashed.
  124.     *ioResult = false;
  125. }
  126.  
  127.  
  128.  
  129.